﻿using Commons.ReturnData;
using OpenAI.Domain.Entities;
using OpenAI.Domain.IRepositories;
using OpenAI.Infrastructure.Requests;

namespace OpenAI.Infrastructure.Services
{
    public class ChatTipService
    {
        private readonly IChatTipRepository repository;

        public ChatTipService(IChatTipRepository repository)
        {
            this.repository = repository;
        }

        public async Task<DataResult<ChatTip>> GetChatTipsAsync(Guid appUserId)
        {
            return await repository.GetChatTipsAsync(appUserId);
        }

        public async Task<SingleResult> DeletedTipByIdAsync(int id)
        {
            return await repository.DeletedTipByIdAsync(id);
        }

        public async Task<SingleResult> CreateTipAsync(CreateChatTipRequest request)
        {
            var tip = new ChatTip(request.Title, request.Content);
            return await repository.CreateTipAsync(tip);
        }
        public async Task<SingleResult> UpdateTipAsync(UpdateChatTipRequest request)
        {
            var tip = await repository.FindChatTipByIdAsync(request.Id);
            tip.Title = request.Title;
            tip.Content = request.Content;
            return await repository.UpdateTipAsync(tip);
        }
        /// <summary>
        /// 获取已经Awesome ChatGPT Prompts的Tips
        /// </summary>
        /// <returns></returns>
        public async Task<DataResult<ChatTip>> GetChatGptTipsAsync()
        {
            return await repository.GetChatTipsAsync(Guid.Empty);
        }
    }
}
